package collectionTaks;

import java.util.ArrayList;
import java.util.List;
/**  练习List集方法：get()、set()、重载remove()、重载add()、subList() */
public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();//创建一个List集合
        //给集合list添加元素
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);//list:[one, two, three, four, five]

        //获取集合list中下标为1的元素
        System.out.println("获取的元素:"+list.get(1));//two

        //替换集合list中下标为3的元素
        list.set(3,"six");
        System.out.println("list替换后:"+list);//[one, two, three, six, five]

        //重载remove()
        list.remove(0);
        System.out.println("list删除元素后:"+list);//[two, three, six, five]
        list.remove("two");
        System.out.println(list);//[three, six, five]

        //重载add()
        list.add(2,"seven");
        System.out.println(list);//[three, six, seven, five]

        System.out.println( list.subList(1,3));//截取集合list中下标1到2的元素(含头不含尾)  [six, seven]














    }
}
